<template>
  <div class="business-manage">
    <el-card>
      <el-form ref="ruleForm" :model="ruleForm" :inline="true" label-width="100px" class="ruleForm">
        <el-form-item label="商家ID：" prop="sellerId">
          <el-input v-model="ruleForm.sellerId" />
        </el-form-item>
        <el-form-item label="审核状态：" prop="examineStatus">
          <el-select v-model="ruleForm.examineStatus">
            <el-option label="审核中" value="IN_REVIEW" />
            <el-option label="审核通过" value="VERIFIED" />
            <el-option label="审核不通过" value="REJECTED" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="isLoading" :data="tableData" border style="width: 100%">
        <el-table-column fixed label="商家ID" prop="user_id" align="center" width="80" />
        <el-table-column label="店铺名称" prop="shop_name" align="center" width="150" />
        <el-table-column label="联系方式" prop="shop_mobile" align="center" width="150" />
        <el-table-column prop="shop_url" label="店铺网址" align="center" width="180" />
        <el-table-column prop="shop_contact" label="店铺联系人" align="center" width="120" />
        <el-table-column prop="shop_wangwang" label="店铺旺旺" align="center" width="120" />
        <el-table-column prop="shop_address" label="店铺地址" align="center" width="200" />
        <el-table-column prop="examine_explain" label="审核说明" width="200" align="center" />
        <el-table-column
            label="状态"
          align="center"
          width="120"
          >
            <template slot-scope="scope">
              {{ scope.row.examine_status | getExamineStatus }}
            </template>
          </el-table-column>
        <el-table-column fixed="right" label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.examine_status === 'REJECTED' || scope.row.examine_status === 'IN_REVIEW'"
              type="text"
              size="small"
              @click="handleExamineClick(scope.row, scope.$index, 'VERIFIED')"
            >通过</el-button>
            <el-button
              v-if="scope.row.examine_status === 'VERIFIED' || scope.row.examine_status === 'IN_REVIEW'"
              type="text"
              size="small"
              @click="handleExamineClick(scope.row, scope.$index, 'REJECTED')"
            >不通过</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :page-size="10"
        layout="total, prev, pager, next, jumper"
        :total="total"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>
<script>
import { sellerShopSearch, sellerShopExamine } from '@/api/user'
export default {
  filters: {
    getExamineStatus(status) {
      let StringType = ''
      switch(status) {
        case 'IN_REVIEW' :
          StringType = '审核中'
          break
        case 'VERIFIED' :
          StringType = '审核通过'
          break
        case 'REJECTED' :
          StringType = '审核不通过'
          break
      }
      return StringType
    }
  },
  data() {
    return {
      ruleForm: {
        pageNumber: 1,
        userStatus: 'IN_REVIEW' // IN_REVIEW-审核中，VERIFIED-审核通过，REJECTED-审核不通过
      },
      tableData: [],
      isLoading: false,
      total: 0,
      dialogVisible: false,
      currentRow: {},
      currentIndex: 0,
      memberExpirationTime: ''
    }
  },
  mounted() {
    this.sellerShopSearch()
  },
  methods: {
    sellerShopSearch() {
      this.isLoading = true
      sellerShopSearch(this.ruleForm)
        .then(res => {
          this.tableData = res.list
          this.isLoading = false
          this.total = res.totalRow
        })
        .catch(() => {
          this.isLoading = false
        })
    },
    onSubmit() {
      this.sellerShopSearch()
    },
    handleClick(row) {},
    handleCurrentChange(page) {
      this.ruleForm.pageNumber = page
      this.sellerShopSearch()
    },
    handleExamineClick(row, index, type) {
      const { id } = row
      this.$prompt(`是否${type === 'VERIFIED' ? '通过' : '不通过'}该店铺的审核？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(({ value }) => {
        sellerShopExamine({
          id,
          examineStatus: type,
          examineExplain: value
        }).then(res => {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.tableData[index].examine_status = type
          this.tableData[index].examine_explain = value
        })
      })
    }
  }
}
</script>
<style lang="scss">
.business-manage {
  .el-card {
    .ruleForm {
      .el-input {
        width: 200px;
      }
      .el-select {
        width: 200px;
      }
    }
  }
}
</style>
